
#include "list.h"
#include "../process.h"

extern sos_pcb *_process_table;

/* delete PID frm the child caches of every process */
void flush_pid(int pid) {
    sos_pcb *cur, *tmp;
    HASH_ITER(hh, _process_table, cur, tmp) {
        if (cur->children != NULL) {
            list_remove_left((cur->children), (SOS_LIST_TYPE) pid);
        }
    };
}


int process_register_child(sos_pcb *parent, sos_pcb *child, int newpid) {
    // Remove PID from all processes that have it cached
    flush_pid(newpid);

    // Add it to the parent's cache
    list_push_back(parent->children, (SOS_LIST_TYPE) newpid); 

    return 0;
}